﻿using System;
using System.Runtime.CompilerServices;
using System.Threading;

namespace JH
{
    /// <summary>
    ///  自定义的轻量任务类
    /// </summary>
    [AsyncMethodBuilder(typeof(JTaskMethodBuilder))]
    public readonly partial struct JTask
    {
        public JTask(Func<bool> condition, CancellationToken token = default,
            DispatchState dispatchState = DispatchState.Default)
        {
            _awaiter = new ConditionAwaiter(condition, token, dispatchState);
        }

        /// <summary>
        /// 等待器
        /// </summary>
        private readonly ConditionAwaiter _awaiter;

        /// <summary>
        ///  给编译器用来支持 await 关键字
        /// </summary>
        public ConditionAwaiter GetAwaiter() => _awaiter;
        
    }
}